﻿using System;
using System.Collections.ObjectModel;

namespace AppGene.DataModel
{
    /// <summary>
    /// The class provides a description for logical primary key. 
    /// The attribute should be applied on properties which are primary key columns.
    /// </summary>
    /// <remarks>
    /// Default, the primary key is an unique, clustered index. 
    /// Users need not to set the primary key name explicitly, 
    /// the name will be generated automatically when the name is not provided.
    /// </remarks>
    [AttributeUsage(AttributeTargets.Class)]
    public class LogicalPrimaryKeyAttribute
        : Attribute
    {
        /// <summary>
        /// Creates a primary key instance.
        /// </summary>
        private LogicalPrimaryKeyAttribute()
        {
            IsClustered = true;
            IsUnique = true;
        }

        /// <summary>
        /// Creates a primary key instance.
        /// </summary>
        /// <param name="column">The column name of primary key.</param>
        public LogicalPrimaryKeyAttribute(string column)
            : this(new string[] { column })
        { }

        /// <summary>
        /// Creates a primary key instance.
        /// </summary>
        /// <param name="column">The column name of primary key.</param>
        /// <param name="column2">The second column name of primary key.</param>
        public LogicalPrimaryKeyAttribute(string column, string column2)
            : this(new string[] { column, column2 })
        { }

        /// <summary>
        /// Creates a primary key instance.
        /// </summary>
        /// <param name="columns">The columns' names for the primary key.</param>
        public LogicalPrimaryKeyAttribute(string[] columns)
            : this()
        {
            this.Columns = new ReadOnlyCollection<string>(columns);
        }

        /// <summary>
        /// Gets the column collection for the primary key.
        /// </summary>
        public ReadOnlyCollection<string> Columns { get; private set; }

        /// <summary>
        /// Indicate if the primary key is a cluster index. Default is true.
        /// </summary>
        public bool IsClustered { get; set; }

        /// <summary>
        /// Indicates if the primary key is an unique index. Default is true.
        /// </summary>
        public bool IsUnique { get; set; }

        /// <summary>
        /// Gets the primary key name.
        /// </summary>
        public string Name { get; set; }
    }
}
